package one.utils;

/*
 * Author: JacksonCoder
 * FileName: pageUtils
 * Version: 1.0.0
 * Date: 2025/7/28
 */
//import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.io.Serializable;
import java.util.List;

public class pageUtils<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 记录总数
     */
    private long totalCount;

    /**
     * 每页记录数
     */
    private long pageSize;

    /**
     * 总页数
     */
    private long totalPage;

    /**
     * 当前页数
     */
    private long currentPage;

    private List<T> list;

    public pageUtils(long currentPage, long pageSize) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
    }

    /**
     * 分页
     *
     * @param list
     * @param totalCount
     * @param pageSize
     * @param totalPage
     * @param currentPage
     */
    public pageUtils(List<T> list, long totalCount, long pageSize, long totalPage, long currentPage) {
        this.list = list;
        this.totalCount = totalCount;
        this.pageSize = pageSize;
        this.totalPage = totalPage;
        this.currentPage = currentPage;
    }

//    public pageUtils(Page<T> page){
//        this.list = page.getRecords();
//        this.totalCount = page.getTotal();
//        this.pageSize = page.getSize();
//        this.currPage = page.getCurrent();
//        this.totalPage = page.getPages();
//    }

    /**
     * 计算分页偏移量和限制数
     *
     * @param pageNum  页码
     * @param pageSize 每页大小
     * @return 包含offset和limit的数组，[0]为offset，[1]为limit
     */
    public static Integer[] calculateOffsetAndLimit(Integer pageNum, Integer pageSize) {
        int offset = 0;
        int limit = Integer.MAX_VALUE;
        if (pageNum != null && pageSize != null) {
            int pn = pageNum;
            int ps = pageSize;
            if (pn > 0 && ps > 0) {
                offset = (pn - 1) * ps;
                limit = ps;
            }
        }
        return new Integer[]{offset, limit};
    }
}
